package com.fyl.pattern.singleton.demo8;

import java.io.Serializable;

/**
 * 静态内部类方式
 */
public class Singleton implements Serializable {
    private static boolean flag = false;
    private Singleton() {
        if (flag) {
            throw new RuntimeException("不能创建多个对象");
        }
        //将flag的值设为true
        flag = true;
    }

    //静态内部类
//    private static class SingletonHolder {
//        private static final Singleton INSTANCE = new Singleton();
//    }
//    public static Singleton getInstance(){
//        return SingletonHolder.INSTANCE;
//    }
}
